[id].vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 导航栏 -->
  5. <HomePageNavigation></HomePageNavigation>
  6. <!-- 列表页广告一 -->
  7. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  8. <!-- 资讯列表 -->
  9. <div class="newsDetail">
  10. <div class="inner">
  11. <div class="innerLeft">
  12. <!-- 面包屑导航 -->
  13. <div class="breadcrumb">
  14. <div class="inner">
  15. <span class="location">当前位置:</span>
  16. <el-breadcrumb :separator-icon="ArrowRight">
  17. <el-breadcrumb-item>
  18. <NuxtLink to="/">首页</NuxtLink>
  19. </el-breadcrumb-item>
  20. <el-breadcrumb-item v-if="parent_name != ''">
  21. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  22. </el-breadcrumb-item>
  23. <el-breadcrumb-item>
  24. <NuxtLink :to="`list-1.html`"> {{ routLevelTitle }}</NuxtLink>
  25. </el-breadcrumb-item>
  26. <el-breadcrumb-item>{{ routeNewsTtitle }}</el-breadcrumb-item>
  27. </el-breadcrumb>
  28. </div>
  29. </div>
  30. <div class="LeftTop">
  31. <h1>{{ newsDetail.title }}</h1>
  32. <p>
  33. 来源: <span>{{ newsDetail.copyfrom }}</span>
  34. 作者: <span>{{ newsDetail.author }}</span>
  35. 发布时间: <span>{{ time }}</span>
  36. </p>
  37. </div>
  38. <div class="leftBottom" v-html="newsDetail.content" v-if="newsDetail.content" @click="openPreview">
  39. </div>
  40. <div v-if="previewVisible" class="preview-modal" @click="closePreview">
  41. <img :src="selectedImage" alt="Preview">
  42. </div>
  43. <!-- 免责声明: -->
  44. <div class="disclaimer" v-if="newsDetail.copyfrom == '本网'">
  45. <p>原文链接:{{ newsDetail.fromurl }}</p>
  46. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  47. </div>
  48. <div v-if="articleChoice">
  49. <HomeSurveyvote></HomeSurveyvote>
  50. </div>
  51. </div>
  52. <div class="innerRight">
  53. <!-- 热点资讯1 -->
  54. <div class="hotList1">
  55. <DetailHotNews></DetailHotNews>
  56. </div>
  57. <!-- 热点资讯2 -->
  58. <div class="hotList2">
  59. <DetailHotNews2></DetailHotNews2>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  65. <!-- 页面底部 -->
  66. <HomeFoot1></HomeFoot1>
  67. </template>
  68. <script setup>
  69. //1.页面依赖 start ---------------------------------------->
  70. import { onMounted } from 'vue'
  71. import { ElBreadcrumb, ElBreadcrumbItem, ElRadio, ElRadioGroup, ElCheckbox, ElCheckboxGroup, ElMessage, ElInput } from 'element-plus'
  72. import { ArrowRight } from '@element-plus/icons-vue'
  73. //1.页面依赖 end ---------------------------------------->
  74. //2.页面路径 start ---------------------------------------->
  75. const route = useRoute();
  76. const articleId = parseInt(route.params.id);
  77. const targetSegment = getRoutePath(1);
  78. let routeId;
  79. //通过导航路径反向查询导航id
  80. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  81. method: 'GET',
  82. query: {
  83. 'pinyin': targetSegment,
  84. },
  85. });
  86. if (getRouteId.code == 200) {
  87. routeId = getRouteId.data.category_id
  88. } else {
  89. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  90. console.log("错误位置:通过url路径查询导航池id")
  91. console.log("后端错误反馈:", getRouteId.message)
  92. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  93. }
  94. //2.页面路径 end ---------------------------------------->
  95. //3.面包屑 start ---------------------------------------->
  96. const parent_name = ref("");
  97. const parent_id = ref("");
  98. const parent_pinyin = ref("");
  99. let getParentNav = async () => {
  100. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  101. method: 'GET',
  102. query: {
  103. 'catid': routeId
  104. },
  105. });
  106. if (listData.code == 200) {
  107. parent_name.value = listData.data.alias;
  108. parent_id.value = listData.data.parent_id;
  109. parent_pinyin.value = listData.data.aLIas_pinyin;
  110. } else {
  111. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  112. console.log("错误位置:获取面包屑导航")
  113. console.log("后端错误反馈:", listData.message)
  114. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  115. }
  116. }
  117. //获得父级栏目详情
  118. getParentNav();
  119. //3.面包屑 end ---------------------------------------->
  120. //4.新闻详情 start ---------------------------------------->
  121. //4.1 资讯详情
  122. const newsDetail = ref({})
  123. const routeNewsTtitle = ref("");
  124. //4.2 发布日期
  125. const time = ref("");
  126. //4.3 路径
  127. const routLevelTitle = ref("");
  128. const routLevelId = ref("");
  129. //4.4 是否展示投票
  130. const articleChoice = ref(false);
  131. //4.5 获取详情
  132. async function getPageData() {
  133. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  134. method: 'GET',
  135. query: {
  136. 'articleid': articleId
  137. },
  138. });
  139. if (mkdata.code == 200) {
  140. //判断是否显示投票
  141. if (mkdata.data.is_survey == 1) {
  142. console.log("本篇文章含有投票!")
  143. articleChoice.value = true;
  144. }
  145. //获取内容
  146. newsDetail.value = mkdata.data;
  147. //获取路径
  148. routLevelTitle.value = newsDetail.value.cat_name;
  149. routLevelId.value = newsDetail.value.category_id;
  150. //获取发布时间
  151. time.value = newsDetail.value.updated_at.split(' ')[0];
  152. //修正标题长度
  153. if (newsDetail.value.title.length >= 20) {
  154. routeNewsTtitle.value = newsDetail.value.title.substr(0, 20) + "...";
  155. } else {
  156. routeNewsTtitle.value = newsDetail.value.title
  157. }
  158. } else {
  159. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  160. console.log("错误位置:获取详情内容")
  161. console.log("后端错误反馈:", mkdata.message)
  162. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  163. }
  164. }
  165. getPageData();
  166. //4.新闻详情 end ---------------------------------------->
  167. //5.广告 start ---------------------------------------->
  168. let adImg1 = ref([]);
  169. let adImg2 = ref([]);
  170. onMounted(async () => {
  171. const { $webUrl, $CwebUrl } = useNuxtApp();
  172. //广告1
  173. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmgw_detail_0001`
  174. const responseAd1 = await fetch(url, {
  175. headers: {
  176. 'Content-Type': 'application/json',
  177. 'Userurl': $CwebUrl,
  178. 'Origin': $CwebUrl
  179. }
  180. });
  181. const resultAd1 = await responseAd1.json();
  182. adImg1.value = resultAd1.data[0];
  183. //广告2
  184. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmgw_detail_0002`
  185. const responseAd2 = await fetch(url2, {
  186. headers: {
  187. 'Content-Type': 'application/json',
  188. 'Userurl': $CwebUrl,
  189. 'Origin': $CwebUrl
  190. }
  191. });
  192. const resultAd2 = await responseAd2.json();
  193. adImg2.value = resultAd2.data[0];
  194. })
  195. //5.广告 end ---------------------------------------->
  196. //6.设置seo信息 start---------------------------------------->
  197. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  198. method: 'GET',
  199. query: {
  200. 'articleid': articleId
  201. },
  202. });
  203. if (setData.code == 200) {
  204. let seoTitle = setData.data.title;
  205. let seoDescription = setData.data.introduce;
  206. let seoKeywords = setData.data.keyword;
  207. let seoSuffix = setData.data.suffix;
  208. let seoName = setData.data.website_name;
  209. useSeoMeta({
  210. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  211. meta: [
  212. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  213. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  214. ]
  215. });
  216. } else {
  217. console.log("获取广告数据失败!", setData.message)
  218. }
  219. //6.设置seo信息 end---------------------------------------->
  220. //8.页面图片放大 start---------------------------------------->
  221. const previewVisible = ref(false)
  222. const selectedImage = ref(' ')
  223. const openPreview = (event) => {
  224. if (event.target.tagName === 'IMG') {
  225. selectedImage.value = event.target.src;
  226. previewVisible.value = true;
  227. }
  228. }
  229. const closePreview = () => {
  230. previewVisible.value = false;
  231. }
  232. //8.页面图片放大 end---------------------------------------->
  233. </script>
  234. <style lang="less" scoped>
  235. @import url('@/assets/css/detail.less');
  236. </style>